//订单查询
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            userExpeditingDeliveryInfo: {
                orderCarts: [],
                total: 0,
                records: 1,
                orderDetail: false,
                conditions: {
                    cartId: '',
                    personName: '',
                    state: '',
                    prodName: '',
                    shopId: vc.getCurrentCommunity().shopId,
                    eventType: '7013'
                },
                address: {
                    username: '',
                    tel: '',
                    address: ''
                },
                curOrderCart: {}
            }
        },
        _initMethod: function () {
            $that._listOrders(DEFAULT_PAGE, DEFAULT_ROWS);
        },
        _initEvent: function () {
            vc.on('userExpeditingDelivery', 'goBack', function (_param) {
                $that.userExpeditingDeliveryInfo.orderDetail = false;
            });
            vc.on('userExpeditingDelivery', 'list', function () {
                $that._listOrders(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            vc.on('pagination', 'page_event', function (_currentPage) {
                $that._listOrders(_currentPage, DEFAULT_ROWS);
            });
        },
        methods: {
            _listOrders: function (_page, _rows) {
                $that.userExpeditingDeliveryInfo.conditions.page = _page;
                $that.userExpeditingDeliveryInfo.conditions.row = _rows;
                var param = {
                    params: $that.userExpeditingDeliveryInfo.conditions
                };
                param.params.cartId = param.params.cartId.trim();
                param.params.prodName = param.params.prodName.trim();
                param.params.personName = param.params.personName.trim();
                //发送get请求
                vc.http.apiGet('/storeOrder/queryStoreOrderCartEvent',
                    param,
                    function (json, res) {
                        var _userExpeditingDeliveryInfo = JSON.parse(json);
                        $that.userExpeditingDeliveryInfo.total = _userExpeditingDeliveryInfo.total;
                        $that.userExpeditingDeliveryInfo.records = _userExpeditingDeliveryInfo.records;
                        $that.userExpeditingDeliveryInfo.orderCarts = _userExpeditingDeliveryInfo.data;
                        vc.emit('pagination', 'init', {
                            total: $that.userExpeditingDeliveryInfo.records,
                            dataCount: $that.userExpeditingDeliveryInfo.total,
                            currentPage: _page
                        });
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            //查询
            _queryOrdersMethod: function () {
                $that._listOrders(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            //重置
            _resetOrdersMethod: function () {
                $that.userExpeditingDeliveryInfo.conditions.cartId = "";
                $that.userExpeditingDeliveryInfo.conditions.prodName = "";
                $that.userExpeditingDeliveryInfo.conditions.personName = "";
                $that._listOrders(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            _openOrderDetailModel: function (_order) {
                vc.jumpToPage('/#/pages/goods/storeOrderCartDetail?orderId=' + _order.orderId + '&cartId=' + _order.cartId);
            }
        }
    });
})(window.vc);
